/**
 * jims
 */
package com.jims.master.modules.csm.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.csm.entity.ExpImportDetail;
import com.jims.master.modules.csm.service.ExpImportDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 入库记录详情Controller
 * @author zhuq
 * @version 2017-03-16
 */
@Controller
@RequestMapping(value = "${adminPath}/csm/expImportDetail")
public class ExpImportDetailController extends BaseController {

	@Autowired
	private ExpImportDetailService expImportDetailService;
	
	@ModelAttribute
	public ExpImportDetail get(@RequestParam(required=false) String id) {
		ExpImportDetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = expImportDetailService.get(id);
		}
		if (entity == null){
			entity = new ExpImportDetail();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(ExpImportDetail expImportDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ExpImportDetail> page = expImportDetailService.findPage(new Page<ExpImportDetail>(request, response), expImportDetail); 
		model.addAttribute("page", page);
		return "modules/csm/expImportDetailIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(ExpImportDetail expImportDetail, Model model) {
		model.addAttribute("expImportDetail", expImportDetail);
		return "modules/csm/expImportDetailForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(ExpImportDetail expImportDetail, Model model) {
	    StringData data=new StringData();
		int i=expImportDetailService.save(expImportDetail);
        if(i>0){
            data.setCode("success");
            data.setData("保存入库详情成功");
        }else{
            data.setCode("error");
            data.setData("保存入库详情失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(ExpImportDetail expImportDetail) {
	    StringData data=new StringData();
		int i=expImportDetailService.delete(expImportDetail);
        if(i>0){
            data.setCode("success");
            data.setData("删除入库详情成功");
        }else{
            data.setCode("error");
            data.setData("删除入库详情失败");
        }
		return data;
	}

}